package com.util;

import com.domain.Employee;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

	public void afterCompletion(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
	}

	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2, ModelAndView arg3) throws Exception {

	}

	public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
			Object arg2) throws Exception {
		Employee employee=(Employee)arg0.getSession().getAttribute("employee");
		if(employee!=null){
			return true;
		}else{
			String str="请先登录再访问！";
			//arg0.setAttribute("msg",str);
			//若用户未登录，则跳转到登陆的控制器
			arg0.getRequestDispatcher("/01login").forward(arg0, arg1);
			return false;
		}

	}

}
